package com.autoglm.android.core.models

import com.google.gson.Gson
import com.google.gson.annotations.SerializedName
import com.google.gson.reflect.TypeToken

/**
 * 任务执行计划，包含一系列执行步骤
 */
data class TaskExecutionPlan(
    @SerializedName("steps") val steps: List<ExecutionStep>,
    @SerializedName("estimatedDurationMs") val estimatedDurationMs: Long,
    @SerializedName("requiredPermissions") val requiredPermissions: List<String> = emptyList(),
    @SerializedName("potentialFailurePoints") val potentialFailurePoints: List<String> = emptyList()
) {
    /**
     * 转换为JSON字符串
     */
    fun toJson(): String {
        return Gson().toJson(this)
    }
    
    companion object {
        /**
         * 从JSON字符串解析
         */
        fun fromJson(json: String): TaskExecutionPlan {
            return Gson().fromJson(json, TaskExecutionPlan::class.java)
        }
    }
}

/**
 * 步骤执行结果数据类
 */
data class StepResult(
    val success: Boolean,
    val errorMessage: String? = null,
    val extraData: Map<String, Any> = emptyMap()
) {
    companion object {
        fun success(extraData: Map<String, Any> = emptyMap()) = 
            StepResult(true, extraData = extraData)
            
        fun failure(message: String) = 
            StepResult(false, errorMessage = message)
    }
}

/**
 * 执行结果数据类
 */
data class ExecutionResult(
    val success: Boolean,
    val errorMessage: String? = null,
    val executionTimeMs: Long = 0,
    val outputData: Map<String, Any> = emptyMap()
) {
    companion object {
        fun success(data: Map<String, Any> = emptyMap()) = 
            ExecutionResult(true, outputData = data)
            
        fun failure(message: String) = 
            ExecutionResult(false, errorMessage = message)
    }
} 